package com.studysystem.repository;

import com.studysystem.entity.CourseTest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CourseTestRepository extends JpaRepository<CourseTest, Long> {
    List<CourseTest> findByCourseId(Long courseId);
    
    @Query("SELECT t FROM CourseTest t WHERE t.course.id = ?1 AND t.passingScore <= ?2")
    List<CourseTest> findPassedTestsByCourseIdAndScore(Long courseId, Integer score);
    
    @Query("SELECT AVG(a.score) FROM TestAttempt a WHERE a.test.id = ?1")
    Double getAverageScoreByTestId(Long testId);
} 